using System;
using UnityEngine;

[Serializable]
public class score : MonoBehaviour
{
	public string spam;

	public float score;

	public string spam2;

	public float scr2;

	public string prefix;

	public GUIText text;

	public int stopped;

	public GameObject Sattack;

	private int tostop;

	private GUITexture energyBar;

	private int energyFull;

	private Animation energyAnim;

	[HideInInspector]
	public bool specialEnabled;

	private bool end;

	private int lstscr;

	public score()
	{
		spam = "spam";
		score = 0.2f;
		spam2 = "spam2";
		scr2 = -0.2f;
		prefix = "Score: ";
		tostop = 1;
	}

	public void Start()
	{
		StateManager.specialAttack = false;
		StateManager.specialEnergy = 0f;
		InvokeRepeating("cscore", 5.5f, 0.4f);
		if (specialEnabled)
		{
			energyBar = GameObject.Find("SpecialEnergy").transform.Find("ProgressBar").GetComponent<GUITexture>();
			energyFull = (int)energyBar.pixelInset.width;
			energyAnim = energyBar.GetComponent<Animation>();
		}
	}

	public void cscore()
	{
		UpdateScore(1);
	}

	public void FixedUpdate()
	{
		if (specialEnabled)
		{
			if (StateManager.specialAttack)
			{
				UpdateEnergy(-0.01f);
			}
			else
			{
				UpdateEnergy(0.035f);
			}
		}
	}

	public void UpdateEnergy(float toAdd)
	{
		StateManager.specialEnergy = Mathf.Clamp(StateManager.specialEnergy + toAdd, 0f, 100f);
		if (!energyBar)
		{
			return;
		}
		Rect pixelInset = energyBar.pixelInset;
		pixelInset.width = Mathf.Clamp((float)energyFull * StateManager.specialEnergy * 0.01f, 5f, energyFull);
		energyBar.pixelInset = pixelInset;
		if (!(StateManager.specialEnergy < 100f))
		{
			if (!energyAnim.isPlaying)
			{
				energyAnim.Play();
			}
			Sattack.GetComponent<SpecialAttack>().Activate();
		}
		else if (!(StateManager.specialEnergy > 5f) && energyAnim.isPlaying)
		{
			energyAnim.Stop();
			float a = 0.51f;
			Color color = energyBar.color;
			color.a = a;
			Color color3 = energyBar.color = color;
		}
	}

	public void UpdateScore(int toAdd)
	{
		if (!end)
		{
			score += toAdd;
			scr2 -= toAdd;
			text.text = prefix + score.ToString("f0");
			if (!(score <= (float)(lstscr + 3000)))
			{
				score = 0f;
			}
			StateManager.score = score;
			StateManager.scr2 = scr2;
			lstscr = (int)score;
		}
	}

	public void finished()
	{
		end = true;
		CancelInvoke();
	}

	public void Main()
	{
		for (int i = 0; (float)i < UnityEngine.Random.value * 50f; i++)
		{
			spam += i;
		}
		for (int j = 0; (float)j < UnityEngine.Random.value * 50f; j++)
		{
			spam2 += j;
		}
	}
}
